<template>
	<view class="diy-page">
		<diy :diyItems="items" :userInfo="userInfo" :pageid="page_id"></diy>
	</view>
</template>

<script>
	import diy from '@/components/diy/diy.vue';
	export default {
		components: {
			diy
		},
		data() {
			return {
				/*页面ID*/
				page_id:0,
				/*diy类别*/
				items:{},
				/*页面信息*/
				page_info:{},
				share:{},
				userInfo:{},
			}
		},
		async onLoad(e) {
			await this.$onLaunched
			this.page_id=e.page_id;
			if(this.page_id==0){
				let sceneInfo = this.getScene(options.scene);
				if(sceneInfo.id){
					this.page_id = sceneInfo.id
				}
			}
			console.log(e.page_id)
			this.getuserInfo();
			this.getData();
		},
		onShareAppMessage(res) { //发送给朋友
			return {
				title: this.share.title?this.share.title:"",
				imageUrl: this.share.imageUrl?this.share.imageUrl:"",
			}
		},
		methods: {
			getScene(scene) {
				let scene_new = decodeURIComponent(scene);
				let info = {};
				var list = scene_new.split("&");
				for (var i = 0; i < list.length; i++) {
					info[list[i].split(":")[0]] = list[i].split(":")[1];
				}
				return info;
			},
			getuserInfo(){
				uni.$u.api.userInfo().then((res) => {
					this.userInfo = res;
				});
			},
			/*获取数据*/
			getData() {
				let self = this;
				uni.$u.api.getPageDataDetail({page_id:self.page_id}).then(res => {
					self.page_info = res.page;
					self.items = res.items;
					self.setPage(self.page_info);
				})
			},
			
			/*设置页面*/
			setPage(page){
				// console.log(page,'=================')
				uni.setNavigationBarTitle({
				    title: page.params.title
				});
				
				let colors = page.style.titleTextColor;
				if(colors=='white'||colors==''){
					//字母要小写
					colors='#ffffff'
				}
				if(colors!='#000000'&&colors!='#ffffff'){
					//字母要小写
					colors='#000000'
				}
				// console.log(colors,'=================')
				// console.log(page.style.titleBackgroundColor,'=================')
				uni.setNavigationBarColor({
				    frontColor: colors,
				    backgroundColor: page.style.titleBackgroundColor
				})
				
				this.share.title = page.params.share_title?page.params.share_title:''
				this.share.imageUrl = page.params.share_img?page.params.share_img:''
			},
		},
		
	}
</script>

<style>
*{
	margin: 0;
	padding: 0;
}
</style>
